-- @owner: cloudsbreak
-- @date: 2025/06/30
-- @testpoint:使用type创建member/static方法，并调用

--setup
@conn  PrimaryDbAmode;

--step1:
create or replace type obj_2 as object (
id int,
name text,
CONSTRUCTOR FUNCTION obj_2( SELF IN OUT obj_2, id integer , name text ) RETURN SELF AS RESULT,
MEMBER FUNCTION f1(a int) return int,
MEMBER FUNCTION f2( SELF IN OUT obj_2, b int) return int,
MEMBER PROCEDURE p1( SELF IN OUT obj_2, b int),
MEMBER PROCEDURE p2,
STATIC FUNCTION s_f1() return int,
STATIC FUNCTION s_f2(b int) return int ,
STATIC procedure s_p1 ,
STATIC procedure s_p2(name text)
);
CREATE OR REPLACE TYPE BODY obj_2 AS
CONSTRUCTOR FUNCTION obj_2( SELF IN OUT obj_2, id integer , name text ) RETURN SELF AS RESULT as
begin
	self.id = id;
	self.name = name;
end;
MEMBER FUNCTION f1(a int) return int as
ret int := a;
begin
	return ret;
end;
MEMBER FUNCTION f2( SELF IN OUT obj_2, b int) return int
as
begin
	raise info 'member function f2 self:%', self;
	return b;
end;
MEMBER PROCEDURE p1( SELF IN OUT obj_2, b int) as
begin
	raise info 'member procedure p1 : name=>%', SELF.name;
end;
MEMBER PROCEDURE p2 as
begin
	raise info 'member procedure p2 : name=>%', SELF.name;
end;
STATIC FUNCTION s_f1() return int as
begin
	raise info 'static function  s_f1 ';
	return 1;
end;
STATIC FUNCTION s_f2(b int) return int as
begin
	raise info 'static function  s_f2  ';
	return b;
end;
STATIC procedure s_p1  as
begin
	raise info 'static function  s_p1 ';
end;
STATIC procedure s_p2(name text)  as
begin
	raise info 'static function  s_p2 name:%',name;
end;
END ;
/
declare
var obj_2 := obj_2(id=>1,name=>'23');
result integer;
begin
result := var.f1(1);
raise info '%',var;
raise info 'member function f1:%',var.f1(1);
raise info 'member function f1:%',var.f2(1);
raise info 'member procedure p1:%', var.p1(1);
var.name := 'vbase';
raise info 'member procedure p2:%', var.p2();
raise info 'static function s_f1:%',obj_2.s_f1();
raise info 'static function s_f2:%',obj_2.s_f2(2);
raise info 'static procedure s_p1:%',obj_2.s_p1();
raise info 'static procedure s_p2:%',obj_2.s_p2('vbase');
end;
/
--teardown:环境清理
drop type obj_2;
